﻿using System;
using System.Collections;
using System.Linq;
using Deanery.Controller.Directories;

namespace Deanery.Controller.PersonData
{
    class OrderController
    {
        private readonly deaneryEntities _db = new deaneryEntities();

        /// <summary>
        /// This method performs INSERT one record to DB in table Orders
        /// PROBLEM: method returns nothing
        /// </summary>
        /// <param name="reccord">ArrayList(one item - one cell value) with data to insert</param>
        public void Insert(ArrayList reccord)
        {
            var typeOrdersObj = new TypeOrdersController();

            var obj = new Order()
            {
                id_orders = new Guid(),
                nv_orders_date = reccord[0].ToString(),
                nv_orders_number = reccord[1].ToString(),
                id_type_orders = typeOrdersObj.FindGuidByName(reccord[2].ToString())
            };

            _db.Orders.AddObject(obj);
            _db.SaveChanges();
        }

        public IQueryable FindByNumber(string number)
        {
            var obj = _db.Orders.Where(t => t.nv_orders_number == number);
            return obj;
        }
    }
}
